/*************************************************************************
 * @File Name: main
 * @Author: Wangjiawei
 * @Version: 1.0
 * @Mail: 2531351704@qq.com
 * @Created Time: 2023/1/26
 * @Description 自平衡自行车
 ************************************************************************/
#include "sys.h"

float My_Voltage;//测量电压值
int Speed_wheel;//动量轮速度
int Speed_N20;//N20速度
int Lastout_Pwm;//最终输出Pwm
float Pitch,Roll,Yaw;//角度
short aacx,aacy,aacz;//加速度传感器原始数据
short gyrox,gyroy,gyroz;//陀螺仪原始数据
int PWM_MAX=90,PWM_MIN=-90;	//PWM限幅变量

int main(void)
{	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	Delay_Init();
	Led_Init();
	Adc_Init();
	OLED_Init();
	uart_init(9600);
	Inertia_wheel_Init();
	Back_motor_Init();
	PWM_Init_TIM1(99,71);//10KHZ
	PWM_Init_TIM3(19999,71);//50HZ
	Encoder_TIM2_Init();
	Encoder_TIM4_Init();
	MPU6050_Init();            //MPU6050初始化  
    while(mpu_dmp_init())
	{
		OLED_ShowString(1,1,"Wite ...",0);
	}  
	mpu_dmp_init();
	OLED_Clear();
	MPU6050_EXTI_Init();
	OLED_ShowString(1,1,"Power:        V ",0);
	OLED_ShowString(2,1,"wheel:          ",0);
	OLED_ShowString(3,1,"N20  :          ",0);
	OLED_ShowString(4,1,"Roll:           ",0);
	Servo_SetAngle(90);//舵机回正

	while(1)
	{
		My_Voltage = 11*(3.3*Get_adc_Average(ADC_Channel_8,10)/4095);//获取电压
		oledPrint(1,8,"%.2f",My_Voltage);
		oledPrint(2,8,"%6d",Speed_wheel);
		oledPrint(3,8,"%6d",Speed_N20);
		oledPrint(4,8,"%4.1f",Pitch);
	}
}
